package co.yixiang.modules.quartz.task;


import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import co.yixiang.modules.shop.service.YxStoreOrderService;
import co.yixiang.modules.supplier.domain.SupplierGoodsSku;
import co.yixiang.modules.supplier.domain.SupplierGoodsSkuLog;
import co.yixiang.modules.supplier.service.SupplierGoodsSkuLogService;
import co.yixiang.modules.supplier.service.SupplierGoodsSkuService;
import co.yixiang.modules.supplier.service.dto.SupplierGoodsSkuDto;
import co.yixiang.modules.supplier.service.dto.SupplierGoodsSkuQueryCriteria;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
@Slf4j
public class SupplierTask {
    private final SupplierGoodsSkuService goodsSkuService;
    private final SupplierGoodsSkuLogService goodsSkuLogService;

    public SupplierTask(SupplierGoodsSkuService goodsSkuService, SupplierGoodsSkuLogService goodsSkuLogService) {
        this.goodsSkuService = goodsSkuService;
        this.goodsSkuLogService = goodsSkuLogService;
    }

    public void run(){
        SupplierGoodsSkuQueryCriteria criteria = new SupplierGoodsSkuQueryCriteria();
        List<SupplierGoodsSkuDto> supplierGoodsSkuDtos = goodsSkuService.queryAll(criteria);
        Date now = DateUtil.parse(DateUtil.today());
        DateTime dateTime = DateUtil.offsetDay(now, -1);
        for (SupplierGoodsSkuDto goodsSkuDto : supplierGoodsSkuDtos) {
            goodsSkuLogService.saveSkuLog(goodsSkuDto,dateTime.getTime());
            System.out.println("商品名:" + goodsSkuDto.getName()+"    时间："+dateTime + "   时间戳："+dateTime.getTime());
        }
    }
}
